/*
 * autostat.js
 * 自动站
 */
;
(function (call) {
	var main = {
		baseUrl: CafeJS.CXT,
		mapId: "tjMap",
		playList: null,
		datepicker: null,
		legendpicker: null,
		latestTime: null,
		selectElements:[],
		router: {
			// getAwsStatData: 'zhfx/station/list/oneElement',
			getAwsStatData: 'shortWarn/autoStation/queryAutoStationDataList',
			getAwsGridData: 'zhfx/station/queryAutoMicaps',
			// getLatestTime: 'zhfx/station/skTime',
			getLatestTime: 'shortWarn/autoStation/queryNewestTimeForAuto',
			stationMainTemplate: '/business/template/station-main.html',
			getElementList:"/hjimg/fxSet/getFxSetInfo",
			//getElementList: "/business/common/data/autostat.json",
			productcfg: "/business/common/json/product.json",
            stationToGrid:'raw/dms/stationDataToRaw',
			initAutoProductPicPop: "/business/template/autoproduct-pic.html",
			queryWZElementList: 'zhfx/station/list/queryWZElementList'
		},
		init: function () {
			this.initView();
			this.bindEvt();
		},
		initView: function () {
			var that = this;
			that.getLatestTime();
			that.initDatePicker();
			$.getJSON(that.router.productcfg, function (cfg) {
				that.getElementList(cfg.autostat);
				that.initProductList();
			})
		},
		// 获取自动站最新实况时间
		getLatestTime: function () {
			var that = this;
            debugger
            if($("#userInfo").data("isMatchuser")){
                that.latestTime = "2022-07-26 10:00";
                return;
            }
			$.ajax({
				url: this.router.getLatestTime,
				type: 'GET',
				dataType: 'json',
				async: false
			}).done(function (res) {
				if (res.code === 200) {
					let str = res.data;
					that.latestTime = new Date(
						parseInt(str.substr(0, 4)),           // 年
						parseInt(str.substr(4, 2)) - 1,       // 月（0-11）
						parseInt(str.substr(6, 2)),           // 日
						parseInt(str.substr(8, 2)),           // 时
						parseInt(str.substr(10, 2)),          // 分
						parseInt(str.substr(12, 2))           // 秒
					).format('yyyy-MM-dd hh:mm');
				}
			})
		},
		initPic: function () {
            var that = this;
            $("#modal_autostst_pic").remove();
            CafeJS.ModalBox({
                id: 'autostst_pic',
                container: 'cafe-busis-container',
                title: "产品图",
                width: 900,
                height: 740,
                m_top: 55,
                m_left: 700,
                hide: true,
                url: that.router.initAutoProductPicPop,
                closed: function () {
                    $("#modal_autostst_pic").remove();
                    $("#modal_autostat ul[iid='STREAM'] .active").removeClass("active");
                }
            });
        },
		// 初始化产品列表
		initProductList: function () {
			var that = this;
			var params = {
				container: '.product-content.autostat',
				data: that.selectElements,
				eleClick: function (ele, oldEle, selected) {
					debugger
					if(selected && ele.ispic && ele.ispic == "true"){
						that.initPic();
						return;
					}
					var ptype = ele.type; //当前要素的类型
					var name = ele.ele_name;

					that.clearLayer([ptype]);
					var pro = {
						name: '自动站_' + name,
						time: that.calcStartTime(ele),
						bussitype: 'autostat',
						ele: ele,
						isGrid: false,
						isSK: true
					}
					if (selected) {
						that.ele = ele;
						// 增加产品图层
						that.addLayerManage(pro);
						that.queryEleData(ele, pro.time);
					} else {
						CafeJS.layerManage.removeLayer(pro); // 删除当前要素的图层
					}
				},
				gridClick: function (ele, oldEle, selected) {
					var eleid = ele.ele_id; //当前要素id
					var oldId = oldEle.ele_id; // 上一个选中要素
					var name = ele.ele_name;

					that.clearGridLayer(oldId);

					var pro = {
						name: '自动站_' + name + '（格）',
						time: that.calcStartTime(ele),
						bussitype: 'autostat',
						ele: ele,
						isGrid: true,
						isSK: true
					}
					if (selected) {
						// 增加产品图层
						that.addLayerManage(pro);
						that.queryAwsGridData(ele, pro.time);

						if (oldId != eleid) {
							name = '自动站_' + oldEle.ele_name + '（格）';
							CafeJS.layerManage.removeLayer({ name: name }); // 删除上一个选中要素的图层
						}
					} else {
						CafeJS.layerManage.removeLayer(pro); // 删除当前要素的图层
					}
				}
			};
			CafeJS.analysis(params);
			if (new Date(that.datepicker.getVal()).getMinutes() !== 0) {
				that.preventEventByMinute(true);
			} else {
				that.preventEventByMinute(false);
			}
		},
		//获取设置选中的要素列表
		getElementList: function (allData) {
			var that = this;
			$.ajax({
				url: that.router.getElementList,
				type: 'post',
				async: false,
				data: {
					"is_sel": "1"
				}
			}).done(function (res) {
				if (res.result.data && res.isSuccessful) {
					debugger
					var selfData = res.result.data;
					var selfElementArr = [];
					var returnArr = [];
					for (var i = 0; i < selfData.length; i++) {
						for (var j = 0; j < selfData[i].elements.length; j++) {
							selfElementArr.push(selfData[i].elements[j].element + "_" + selfData[i].elements[j].name);
						}
					}
					for (var k = 0; k < allData.length; k++) {
						var contentArr = [];
						for (let y = 0; y < allData[k].content.length; y++) {
							var key = allData[k].content[y].ele_id + "_" + allData[k].content[y].ele_name;
							if (selfElementArr.indexOf(key) > -1) {
								contentArr.push(allData[k].content[y]);
							}
						}
						allData[k].content = contentArr;
						if (contentArr.length > 0) {
							returnArr.push(allData[k]);
						}
					}
					that.selectElements = returnArr;
				} else {
					that.selectElements = allData;
				}
			})
		},

		// 初始化时间控件
		initDatePicker: function () {
			var _this = this;
			this.datepicker = CafeJS.Datepicker({
				appendTo: "#datepicker-autostat",
				curDate: _this.latestTime,
				type: 9,
				timeInterval: 5,
				ttimeInterval: 1,
				autoPush: true,
				call: function (val) {
					$(".ranking-head span").empty().text(new Date(val).format('yyyyMMdd hhmm'));
					if (new Date(_this.datepicker.getVal()).getMinutes() !== 0) {
						_this.preventEventByMinute(true);
					} else {
						_this.preventEventByMinute(false);
                    }
                    _this.queryMultiEleData();
				},
				updateDateCall: function () {
					if (new Date(_this.datepicker.getVal()).getMinutes() !== 0) {
						_this.preventEventByMinute(true);
					} else {
						_this.preventEventByMinute(false);
					}
				}
			});
			$("#datepicker-autostat").show();
		},
		//当分为00时，元素不能点击，置灰
		preventEventByMinute: function (flag) {
			$(".product-list li").each(function (index) {
				var $obj = $(this);
				var eleId = $obj.data("pro").ele_id;
				if (eleId === "Snow_Depth") {
					if (flag) {
                        if ($obj.hasClass("active")) {
                            $obj.click();
                        }
						$obj.addClass("preventEventLi");
						$obj.children().addClass("preventEvent");
						$obj.attr("title", "整点统计数据");
					} else {
						$obj.removeClass("preventEventLi");
						$obj.children().removeClass("preventEvent");
						$obj.attr("title", "");
					}
				}
			})
		},
		// 初始化图例
		initLegentpicker: function (ele, appendTo) {
			var that = this;
			var layers = that.getModels(ele);
			var layerIds = [];
			$.each(layers, function (i, m) {
				layerIds.push(m.id);
			});
			CafeJS.legentPicker = CafeJS.Legentpicker({
				appendTo: appendTo,
				gisId: that.mapId,
				layerId: layerIds,
				totalWidth: 400,
				h_legend: 15,
				seq: 'decrease',
				productId: ele.color_id,
				isShowSlider: true
			});
		},
		// 初始化播放列表
		initPlayList: function (pro) {
			var that = this;
			var startTime = pro.time;

			var layers = this.getModels(pro.ele);
			var interval = pro.ele.interval || 5;
			this.playList = CafeJS.Timeline3({
				appendTo: "#a-m-timeline",
				curDate: startTime,
				type: 1,
				pro: pro,
				dateOpt: {
					dateFmt: 'yyyy-MM-dd hh:mm',
					timeInterval: interval,
					customHm: []
				},
				timeInterval: interval,
				layers: layers,
				gisId: that.mapId,
				call: function (pro) {
					CafeJS.layerManage.updateLayer(pro);
					var ele = pro.ele;
					that.ele = ele;
					if (pro.isGrid) {
						that.queryAwsGridData(ele, pro.time);
					} else
						that.queryEleData(ele, pro.time);
				},
				getPlayData: function (pro, timeArr) {
					if (pro.isGrid) {
						var ele = pro.ele;
						that.queryAwsGridData(ele, timeArr);
					}
				}
			});
		},
		// 查询已选择要素
		queryMultiEleData: function () {
			var that = this;
			var pro, time;
			$(".autostat .product-list li.active").each(function (i, ele) {
				pro = $(ele).data('pro');
				time = that.calcStartTime(pro);
				CafeJS.layerManage.updateLayerTime(time, 'autostat', null, pro.ele_id);
				that.queryEleData(pro, time);
			});
			$(".autostat .product-list i.active").each(function (i, ele) {
				pro = $(ele).parent().data('pro');
				time = that.calcStartTime(pro);
				CafeJS.layerManage.updateLayerTime(time, 'autostat', null, pro.ele_id);
				that.queryAwsGridData(pro, time);
			});
		},
		// 查询要素数据
		queryEleData: function (ele, time) {
			var that = this;
			var ptype = ele.type;
			that.clearLayer([ptype]);
			that.queryAwsStatData(ele, time);
			that.queryWZElementList();
		},
		// 查询站点数据
		queryAwsStatData: async function (ele, time) {
			var that = this;
			time = new Date(time).format('yyyy-MM-dd hh:mm:ss');
			var element = ele.ele_id;

			try {
				let res = await $.ajax({
					url: that.router.getAwsStatData,
					type: "GET",
					data: {
						element: element,
						time: time
					},
					contentType: 'application/json'
				});

				if (res.code != 200) return;

				if (!res.data) {
					alert(`该时间点${ele.ele_name}没有数据`);
					return;
				}

				if ($('.cafe-busis-toolsbar #zhsk.active').length === 0) return;
				var data = res.data; 
				if (!data || data.length === 0){
					alert("该时间点"+ele.ele_name+"没有数据");
					return
				};
				var eleType = ele.type;
				var statTypes = [0, 1, 2, 3, 4, 5, 6], dataArr = {};
				statTypes.forEach(function (type, index) {
					dataArr[type] = {};
				})
				data.forEach(function (station, index) {
					if (!station.lon) return;
					if (station.val >= 999990) return;
					if (eleType == 'TP'){
						if (station.val == 0){
							return;
						};
						station.val = parseFloat(station.val.toFixed(1))
					};
					station.options = {
						labelStyle: $.extend(false, { fillStyle: that.getLabelObj(eleType).scolor, size: 14, textAlign: "center" }, that.getLabelObj(eleType)),
						bgStyle: { fillStyle: "rgba(0,0,0,0)", strokeStyle: "rgba(0,0,0,0)", radius: 3 }
					}
					if (dataArr[station.stationType][eleType]) {
						dataArr[station.stationType][eleType].push(station)
					} else {
						dataArr[station.stationType][eleType] = [];
						dataArr[station.stationType][eleType].push(station)
					}
				})
				var statArr = [];
				statTypes.forEach(function (type, index) {
					if ($.isEmptyObject(dataArr[type])) {
						delete dataArr[type];
					} else {
						statArr.push(type);
					}
				})
				if (statArr.length === 0) {
					return;
				}
				var dataObj = {
					dataArr: dataArr,
					eleTypes: [eleType],
					statTypes: statArr
				}
				debugger
				GIS.Station.showElements(that.mapId, dataObj, that.getStatStyleObj(), {}, null, null, { 'cx': true });
				GIS.Station.eleShowControl(that.mapId, CafeJS.tqfx.toolsBar.getUnActiveStationType(), ['WIND', 'VIS', 'TMP', 'TP', 'RH', 'SP'], 'hide');
				if (eleType == 'WIND') {
					CafeJS.tqfx.statSignControl(CafeJS.tqfx.toolsBar.isToolActive('windbar'), "");
					CafeJS.tqfx.statSignControl(CafeJS.tqfx.toolsBar.isToolActive('windspeed'), "TxtBg");
				}
				// 站点详情
				GIS.MouseEvent.Bind(that.mapId, that.getStatLayerIds(), function(stationInfo) {
					window.analysis = {
						"stationId": stationInfo.stationId,
						"type": "10min",
						"currentTime": that.datepicker.getVal(),
						"stationName": stationInfo.stationName,
						"stationLon":stationInfo.lon,
						"stationLat":stationInfo.lat
					};
					CafeJS.tqfx.showDateAnalysis("dateAnalysis");
				}, function(stationInfo) {
					return stationInfo.stationName;
				}); 
			} catch (err) {
				console.error('queryAwsStatData======>', err);
			}
		},
		// 获取自动站格点数据
		queryAwsGridData: function (ele, time) {
			var that = this;
			time = new Date(time).format('yyyy-MM-dd hh:mm:ss');
			var element = ele.grid_id;
            if(ele.stationToGrid){
				that.getStationToGrid(ele,time);
				return;
			}
			if (!element) return;
			var param = {
				skTimes: time,
				element: element
			}
			CafeJS.ajax({
				url: that.router.getAwsGridData,
				params: param,
				type: "GET",
				contentType: 'application/json',
				success: function (e) {
					var arrayBuffer = e.response;
					if (arrayBuffer.byteLength === 0) {
						alert("该时间点"+ele.ele_name+"没有数据");
						that.clearGridLayer(element);
						return;
					}
					that.drawGridRawMap(arrayBuffer, ele);
				}
			})
		},
        getStationToGrid(ele,time){
            var that = this;
            var element = ele.ele_id;
            that.clearGridLayer(ele.grid_id);
            $.ajax({
                url: that.router.getAwsStatData,
				//url:'business/common/data/windData.json',
                type: "GET",
                data: {
                    element: element,
                    time: time
                },
                contentType: 'application/json',
                success: function (res) {
                    if (res.code != 200){
                        alert('查询失败');
                        return;
					}
                    var data = res.data;
                    if (!data || data.length === 0){
                        alert("该时间点"+ele.ele_name+"没有数据");
                        return
                    };
                    CafeJS.ajax({
                        url: that.router.stationToGrid,
                        params: {
                        	json:JSON.stringify(data),
                        	post:'0'
						},
                        type: "POST",
                        success: function (e) {
                            var arrayBuffer = e.response;
                            if (arrayBuffer.byteLength === 0) {
                                alert("该时间点"+ele.ele_name+"没有数据");
                                return;
                            }
                            var typeArr = that.getModels(ele);
                            var colorObj = CafeJS.Legentconfig().cfg()[ele.color_id] || {};
                            // 显示色斑和数值 colorObj.areaCode = 'Haihe';
                            colorObj.cutFlag = true;
                            GIS.GridShow.showByTypes_raw(that.mapId, typeArr,arrayBuffer, {}, colorObj);
                            CafeJS.legentPicker.updateLegentRange(typeArr,that.mapId,null);
                        }
                    })
                },
                error: function () {
                    loading.remove();
                }
            })

		},
		// 绘制格点色斑图
		drawGridRawMap: function (data, ele) {
			var that = this;
			var typeArr = this.getModels(ele);
            var colorObj = CafeJS.Legentconfig().cfg()[ele.color_id] || {};
            if (ele.models == 'isoline') {
                gridUtil.createIsoline(data, typeArr[0].id, colorObj.levels, GLMap.geometryData.areaconfig.Haihe.rings);
            } else {
				// 显示色斑和数值
				colorObj.cutFlag = true;
				colorObj.areaCode = 'Haihe';
                GIS.GridShow.showGrid(this.mapId, typeArr, data, {}, colorObj);
			}
			var min = ele.type == 'TP'?0.1:null;
			CafeJS.legentPicker.updateLegentRange(typeArr,that.mapId,min);
		},
		// 增加产品图层
		addLayerManage: function (pro) {
            debugger
			var that = this;
			if (CafeJS.layerManage) {
				CafeJS.layerManage.addLayer(pro);
			} else {
				CafeJS.layerManage = CafeJS.LayerManage({
					appendTo: "#c-b-layermanage",
					mapId: that.mapId,
					proInfo: pro,
					call: function (pro) {
						CafeJS[pro.bussitype].initPlayList(pro);
					},
					more: function (pro) {
						CafeJS[pro.bussitype].stationView(pro);
					},
					close: function (pro) {
						CafeJS[pro.bussitype].delLayer(pro);
					}
				})
			}
			if (pro.isGrid && pro.ele.models != "isoline") {
				that.initLegentpicker(pro.ele, '.cafe-layer-item.active');
			}
		},
		// 根据时间间隔获取开始时间
		calcStartTime: function (ele) {
			var time = new Date(this.datepicker.getVal());
			switch (ele.interval) {
				case 10:
					time.setMinutes(Math.floor(time.getMinutes() / 10) * 10);
					break;
				case 60:
					time.setMinutes(0);
					break;
			}
			return time.format('yyyy-MM-dd hh:mm');
		},
		// 删除图层后取消要素选择
		delLayer: function (pro) {
			var eleid = pro.ele.ele_id;
			var ptype = pro.ele.type;
			if (pro.isGrid) {
				var $grid = $(".autostat .product-list i.active");
				if ($grid.parent().data('eleid') == eleid)
					$grid.click();
				return false;
			}
			$(".autostat .product-list li.active").each(function () {
				if ($(this).data('eleid') == eleid) {
					$(this).click();
					return false;
				}
			})
		},
		// 清除单要素GIS图层
		clearLayer: function (eleid) {
			debugger
			GIS.Station.eleShowControl(this.mapId, [0, 1, 2, 3, 4, 5, 6], eleid, "delete");
		},
		// 清除格点GIS图层
		clearGridLayer: function (eleid) {
			var layerIds = [];
			GLMap.layerIds.forEach(function (layerId) {
				if (layerId.indexOf('autostat-layer') != -1 && layerId.lastIndexOf(eleid) != -1) {
					layerIds.push(layerId);
				}
			})
			GIS.LayerControll.deleteLayer(this.mapId, layerIds);
		},
		// 获取站点GIS图层id
		getStatLayerIds: function () {
			var layerIds = [];
			$(".autostat .product-list li.active").each(function () {
				var eleid = $(this).data("pro").type;
				[0, 1, 2, 3, 4, 5, 6].forEach(function (st) {
					layerIds.push(eleid + st + "Stat");
				});
			});
			return layerIds;
		},
		// 获取要素样式
		getModels: function (ele) {
			var models = [];
			$.each(ele.models.split(","), function (i, m) {
				var layerId = "autostat-layer-" + m + "-" + ele.ele_id;
				models.push({
					type: m,
					visible: true,
					uv: false,
					wd: (ele.type == 'WIND' && !ele.stationToGrid) ? true : false,
					id: layerId
				});
			});
			return models;
		},
		bindEvt: function () {
		},
		// 获取站点类型样式
		getStatStyleObj: function () {
			var styleObj = {
				minLevel: 0,
				size: 8,
				font: { color: { a: 1, r: 1, g: 0, b: 0 }, xOffset: 0, yOffset: 20, size: '16px', length: 18, width: 8 }
			};
			return {
				//基本站
				0: $.extend(false, styleObj, { color: { r: 224, g: 10, b: 10, a: 255 }, size: 8 }),
				//区域站
				1: $.extend(false, styleObj, { color: { r: 76, g: 77, b: 78, a: 255 }, size: 6 }),
				//海岛站
				2: $.extend(false, styleObj, { color: { r: 0, g: 0, b: 0, a: 255 }, size: 8 }),
				//浮标站
				3: $.extend(false, styleObj, { color: { r: 0, g: 0, b: 0, a: 255 }, size: 8 }),
				//船舶站
				4: $.extend(false, styleObj, { color: { r: 0, g: 0, b: 0, a: 255 }, size: 8 }),
				//平台站
				5: $.extend(false, styleObj, { color: { r: 0, g: 0, b: 0, a: 255 }, size: 8 }),
				//微智站
				6: $.extend(false, styleObj, { color: { r: 0, g: 96, b: 214, a: 255 }, size: 8 })
			};
		},
		// 获取要素样式
		getLabelObj: function (eleType) {
			var labelObj = {
				"WIND": { xOffset: 0, yOffset: 0, scolor: "rgb(0,0,0)" },
				"VIS": { xOffset: 35, yOffset: 20, scolor: "rgb(70,135,33)" },
				"TMP": { xOffset: 0, yOffset: 20, scolor: "rgb(200,30,70)" },
				"TP": { xOffset: 35, yOffset: 0, scolor: "rgb(74,140,84)" },
				"RH": { xOffset: 0, yOffset: -20, scolor: "rgb(101,83,215)" },
				"SP": { xOffset: 35, yOffset: -20, scolor: "rgb(157,78,231)" }
			}
			return labelObj[eleType];
		},
		queryWZElementList: async function () {
			let arr = [];
			$('#station .cas-station.active').each(function() {
				arr.push($(this).attr('type'));
			});
			if (!arr.includes('6')) return;
			let that = this;
			let ele = that.ele;
			let time = that.calcStartTime(ele);
			time = new Date(time).format('yyyy-MM-dd hh:mm:ss');
			var element = ele.ele_id;
			try {
				let res = await $.ajax({
					url: that.router.queryWZElementList,
					type: "GET",
					data: {
						element: element,
						time: time
					},
					contentType: 'application/json'
				});
	
				if (!res.isSuccess) return;
	
				if (!res.data) {
					alert(`该时间点${ele.ele_name}没有数据`);
					return;
				}
	
				if ($('.cafe-busis-toolsbar #zhsk.active').length === 0) return;
				if (!res.isSuccess) return;
				var data = res.data; 
				if (!data || data.length === 0){
					alert("该时间点"+ele.ele_name+"没有数据");
					return
				};
				var eleType = ele.type;
				var statTypes = [6], dataArr = {};
				statTypes.forEach(function (type, index) {
					dataArr[type] = {};
				})
				data.forEach(function (station, index) {
					if (!station.lon) return;
					if (station.val >= 999990) return;
					if (eleType == 'TP'){
						if (station.val == 0){
							return;
						};
						station.val = parseFloat(station.val.toFixed(1))
					};
					station.options = {
						labelStyle: $.extend(false, { fillStyle: that.getLabelObj(eleType).scolor, size: 14, textAlign: "center" }, that.getLabelObj(eleType)),
						bgStyle: { fillStyle: "rgba(0,0,0,0)", strokeStyle: "rgba(0,0,0,0)", radius: 3 }
					}
					if (dataArr[station.stationType][eleType]) {
						dataArr[station.stationType][eleType].push(station)
					} else {
						dataArr[station.stationType][eleType] = [];
						dataArr[station.stationType][eleType].push(station)
					}
				})
				var statArr = [];
				statTypes.forEach(function (type, index) {
					if ($.isEmptyObject(dataArr[type])) {
						delete dataArr[type];
					} else {
						statArr.push(type);
					}
				})
				if (statArr.length === 0) {
					return;
				}
				var dataObj = {
					dataArr: dataArr,
					eleTypes: [eleType],
					statTypes: statArr
				}
				GIS.Station.showElements(that.mapId, dataObj, that.getStatStyleObj(), {}, null, null, { 'cx': true });
				GIS.Station.eleShowControl(that.mapId, CafeJS.tqfx.toolsBar.getUnActiveStationType(), ['WIND', 'VIS', 'TMP', 'TP', 'RH', 'SP'], 'hide');
				if (eleType == 'WIND') {
					CafeJS.tqfx.statSignControl(CafeJS.tqfx.toolsBar.isToolActive('windbar'), "");
					CafeJS.tqfx.statSignControl(CafeJS.tqfx.toolsBar.isToolActive('windspeed'), "TxtBg");
				}
				// 站点详情
				GIS.MouseEvent.Bind(that.mapId, that.getStatLayerIds(), function(stationInfo) {
					window.analysis = {
						"stationId": stationInfo.stationId,
						"type": "10min",
						"currentTime": that.datepicker.getVal(),
						"stationName": stationInfo.stationName,
						"stationLon":stationInfo.lon,
						"stationLat":stationInfo.lat
					};
					CafeJS.tqfx.showDateAnalysis("dateAnalysis");
				}, function(stationInfo) {
					return stationInfo.stationName;
				}); 
			} catch (err) {
				console.error('queryWZElementList======>', err)
			}
		}
	};
	if (typeof call === 'function') {
		CafeJS.autostat = main;
		call(main);
	}

})(function (main) {
	CafeJS.models(['datepicker', 'legentpicker', 'legentconfig', 'ajax', 'squarelegend', 'timeLine3'], function () {
		main.init();
	});
});
